JkDefrag v3.34

     JkDefrag is a disk defragmenter and optimizer for Windows 2000/2003/XP/Vista/X64. Completely automatic and very easy to use, fast, low overhead, with several optimization strategies, and can handle floppies, USB disks, memory sticks, and anything else that looks like a disk to Windows. Included are a Windows version, a commandline version (for scheduling by the task scheduler or for use from administrator scripts), a screensaver version, a DLL library (for use from programming languages), versions for Windows X64, and the complete sources.
Free GNU software

Download

JkDefrag is completely free, no cost, no time limit. If you've payed for your copy then you've been scammed! The executables are released under the  *  GNU General Public License, and the sources are released under the  *  GNU Lesser General Public License.

Release date: February 1, 2008
 *  JkDefrag-3.34.zip Download for Windows 2000/2003/XP/Vista 465kb
 *  JkDefrag64-3.34.zip Download for X64 versions of Windows 2003/XP/Vista 455kb
 *  JkDefrag-src-3.34.zip Download sources for Microsoft Visual C++ 2005 398kb

Tip: For translated versions see the "Contributed by other people" chapter at the end of this page.
Tip: Don't know how to unpack a zip file? Use  *  7-zip.
Tip: Check out the  *  JkDefrag forum for the latest news!

Install

There is no "setup" or "install" and no configuration file. All you have to do is download the zip and unpack anywhere you like. The programs are ready to run, even from memory stick or cdrom. The zip contains the following 3 programs:

JkDefrag.exe
Windows version. This is what most people will use. No installation or configuration necessary, it's ready to run and will automatically process all the mounted, writable, fixed volumes on your computer
JkDefragCmd.exe
Commandline version. Specially designed to be run automatically in the background, or from administrator scripts. See the "Commandline" chapter below for a list of commandline options, and the "Frequently Asked Questions" on how to run it automatically with the Windows Scheduler.
JkDefragScreenSaver.scr + JkDefragScreenSaver.exe
Screen saver version. Move (or copy) these two files to the "windows" folder on your harddisk (usually "c:\Windows\" or "c:\Winnt\"). It will automatically become visible in the list of screen savers as "JkDefrag screensaver" and can be used just like any other screensaver (right-click somewhere on your desktop and select Properties/Personalize, then select the Screen Saver tab).
Note: on Vista the screensaver only works with User Account Control turned off (see Control Panel, User Accounts, Turn User Account Control on or off).
Note: screen savers do not lengthen the life span of CRT and LCD monitors, contrary to popular belief. It is better to let the monitor be turned off by the Windows energy saving settings.

Permissions
JkDefrag needs "full control" permissions to all files and disks that it must defragment/optimize. On a default Windows system the "administrator" userid has full permissions to all files and disks. Users can also run JkDefrag, but then it can only defragment/optimize the files and disks for which the user has "full control".
Note: On Vista right-click the JkDefrag program and select "run as administrator".
Stopping
All versions of JkDefrag can be stopped safely at any time, there is no risk of losing data or corrupting your disk. You can use all the usual ways to stop a Windows program, such as pressing ALT-F4, clicking the 'x' in the top-right corner, via the pull-down menu in the taskbar, or by killing the program via the task manager or another utility. The commandline program can be stopped the same way, plus by pressing CTRL-C, or BREAK. It may take a bit of time for the program to actually stop, JkDefrag will finish the current file in the background.
Logfile
JkDefrag writes all messages to a logfile called "JkDefrag.log", or "JkDefragCmd.log", or "JkDefragScreenSaver.log", depending on which version you are using. You can inspect the logfile if you want, it's a flat-text file. The logfile is automatically cleared when the program starts, it does not grow to infinity.
Tip: you can use environment variables in the name of the logfile, for example "-l %COMPUTERNAME%.log".
The Windows version of JkDefrag shows a high-detail map of the harddisk, refreshed 3 times per second. Bottom-left of the window is the beginning of the harddisk. The colors used are:
  • Black: empty
  • Green: regular files, unfragmented
  • Dark green: spacehogs, unfragmented
  • Yellow: fragmented
  • Red: unmovable
  • White: busy
  • Pink: MFT reserved zone (NTFS only)
  • Gray: in use by unknown data

Snapshot of JkDefrag in action. The program is completely automatic,
there are no buttons and no pull-down menu's.

Tip: Cleanup old junk from your harddisk before running JkDefrag, for example with "Start -> Programs -> Accessories -> System Tools -> Disk Cleanup", or with something like the freeware  *  CCleaner program.

Tip: Reboot before running JkDefrag. This will release files that are in use, so they can be defragmented. You can also run JkDefrag in Windows safe mode (press F8 while booting) to defrag even more files.

Tip: Stop your real time virus scanner before running JkDefrag. Virus scanners check all disk activity, making defragmentation and optimization very slow.

Tip: Move the swap file to another volume, reboot, defragment, and move the swap file back. If you don't have a second volume then temporarily make the swap file small, for example 100Mb.

Tip: If an application (for example a database) prevents certain files from being defragmented then stop the application, run JkDefrag for the particular data directory only, and restart the application.

Tip: Package unused files with a packager such as  *  7-zip . The packagefile not only takes less harddisk space, but will also defragment and optimize much faster than the individual files. Note: This does not apply to Windows NTFS compression, which will actually make defragmentation and optimization a lot slower.

Tip: Buy the biggest harddisk you can afford. Investing in a bigger harddisk gives more speed-per-dollar than investing in a faster CPU or more memory.

Tip: The first partition on a harddisk is significantly faster than other partitions. Try to use other partitions only for "SpaceHog" data (see "What are SpaceHogs?").

Tip: If you have 2 physical harddisks (of the same speed), then place the pagefile on the first partition of the second harddisk.

How it works

JkDefrag is based on the standard defragmentation API by Microsoft, a system library that is included in Windows 2000, 2003, XP, and Vista. Most defragmenters are based on this API, including the free defragmenter that comes with Windows and many commercial defragmenters. Basically all JkDefrag does is send "move this file to that location" commands to the API. JkDefrag does not modify the disk by itself, and is therefore extremely solid.

Defragmentation and optimizing will not only make a harddisk faster, but also lengthen it's life span. The disk will have less work to do and therefore have less wear and tear. Secondly, the sorting optimization strategies (see the "-a" option) will refresh all the magnetic data on your harddisk. However, defragmenting and optimizing is work, so excessive defragmenting and optimizing can actually cause more wear and tear than it prevents. JkDefrag is therefore set for "fast" optimization by default, intended to be used on a daily basis. The other optimizations should only be used occasionally.

Phase 1: Analyze
JkDefrag has to scan all the files on the disk to determine if they are fragmented and where they are. A second step inside this phase will apply the exclude masks and determine which files are SpaceHogs.
Phase 2: Defragment
All fragmented files are defragmented, simply by moving them to the first gap on the disk that is big enough. If there is no gap big enough then the defragmenter will reduce the number of fragments in the file by moving as much of the file as possible into the largest gaps available.
Phase 3: Optimize
  • On most harddisks the beginning of the harddisk is considerably faster than the end, sometimes by as much as 200 percent! See the link to "HD Tune" in the "See Also" chapter for a nice little free program to measure your disk. The default JkDefrag optimization strategy therefore moves all files to the beginning of the volume. It is intended for daily use and will simply fill gaps with files from above, very quick and with very little data movement.
  • JkDefrag classifies files into 3 zones: directories (zone 1), regular files (zone 2), and SpaceHogs (zone 3). Directories are perhaps the most accessed data on disk, so zone 1 is placed at the beginning of the harddisk. After the directories comes a free area (see below), then zone 2 with regular files, another free area, and then zone 3 with SpaceHogs (less important files that take up a lot of space). The beginning and end of the zones is determined automatically, see the "-f" option.
  • A running computer will create and delete temporary files like there is no tomorrow. If the harddisk were completely optimized then the only place for new temporary files would be behind all the other data. Which is rather slow. So JkDefrag maintains a free space of 1% of the total disk space between zone 1 (directories) and zone 2 (regular files), and between zone 2 and zone 3 (SpaceHogs).
  • Sorting the files on your disk can give you even more speed. There are several sorting strategies to choose from (see the "-a" options). These are all very slow and intended for occasional use only.
  • Windows reserves a percentage of the disk for the MFT (Master File Table), but can place normal files there if the rest of the disk is full. The files will remain there, even when there is enough space again. JkDefrag looks for files in the MFT reserved space and moves them to normal diskspace, making the reserved space available again for the MFT.
When JkDefrag is running you will see lot's of messages zipping by showing you exactly what is happening. The messages are also stored in the logfile ("JkDefrag.log" or "JkDefragCmd.log") for later inspection. The logfile may also contain warning messages, for example when a file could not be moved. This is normal, no need to worry. Windows has many system files that cannot be moved while Windows is running.

Commandline

JkDefrag is completely automatic.
The commandline options are not needed for normal use.

JkDefrag is ready to run, just click the "JkDefrag" program. Default behavior is to automatically process all the mounted, writable, fixed volumes on your computer. You can change this behavior with the following commandline options:

For example:     JkDefrag.exe -a 7 -d 2 -q c: d:
 
-a N     The action to perform. N is a number from 1 to 11, default is 3:
1 = Analyze, do not defragment and do not optimize.
2 = Defragment only, do not optimize.
3 = Defragment and fast optimize [recommended].
5 = Force together.
6 = Move to end of disk.
7 = Optimize by sorting all files by name (folder + filename).
8 = Optimize by sorting all files by size (smallest first).
9 = Optimize by sorting all files by last access (newest first).
10 = Optimize by sorting all files by last change (oldest first).
11 = Optimize by sorting all files by creation time (oldest first).
-e "mask"     Exclude files and/or directories that match the mask. The items will not be defragmented and will not be moved. Use wildcards '*' and '?' in the mask to match a set of files or directories. If the mask contains a space then it must be enclosed in double-quotes. Some examples:
JkDefrag -e *.avi -e *.zip -e *.log
JkDefrag -e D:\MySQL\Data\*
-u "mask"     Files that match a mask will be moved to the SpaceHogs area. The program has a built-in list for all files bigger than 50 megabytes, files not accessed in the last month, archives, files in the recycle bin, service pack files, and some others. Disable this list by specifying the special mask "DisableDefaults". Use wildcards '*' and '?' in the mask to match a set of files or directories. If the mask contains a space then it must be enclosed in double-quotes. Some examples:
JkDefrag -u *.avi -u *.zip -u *.log
JkDefrag -u D:\MySQL\Data\*
-s N     Slow down to N percent (1...100) of normal speed. Default is 100.
-f N     Set the size of the free spaces to N percent (0...100) of the size of the volume. The free spaces are room on disk for temporary files. There are 2 free spaces, between the 3 zones (directories, regular files, SpaceHogs). Default is 1% (per free space).
-d N     Select a debug level, controlling the messages that will be written to the logfile. The number N is a value from 0 to 6, default is 1:
0 = Fatal errors.
1 = Warning messages [default].
2 = General progress messages.
3 = Detailed progress messages.
4 = Detailed file information.
5 = Detailed gap-filling messages.
6 = Detailed gap-finding messages.
-l "filename"     Specify a filename for the logfile. Default is "JkDefrag.log" and "JkDefragCmd.log". Specify empty string "" (two double-quotes) to disable the logfile.
-h     [commandline version only] Show a short help text.
-help     [commandline version only] Show a short help text.
--help     [commandline version only] Show a short help text.
/?     [commandline version only] Show a short help text.
-q     [windows version only] Quit the program when it has finished.
items     The items to be defragmented and optimized, such as a file, directory, disk, mount point, or volume, including removable media such as floppies, USB disks, memory sticks, and other volumes that behave like a harddisk. Wildcards '*' and '?' are allowed to select a set of files. If the item contains a space then it must be enclosed in double-quotes. Some examples:
JkDefrag C: D:
JkDefrag f:\*.log D:\MySQL\Data\*

Fast optimization
This optimization strategy is designed for every day use. It moves a minimum of data on the harddisk and finishes very quickly, but will not fill all the gaps on the disk. The strategy scans for gaps on the disk and fills them with files from above.
Sorted optimization
All the sorting optimizations WILL CREATE FRAGMENTS. This is by design, it is not a bug. For more info see the Frequently Asked Questions.
These sorting optimizations are for incidental use once in a while. They take a lot of running time and data movement because they rewrite all the data on the disk. The strategies vacate a small area on disk and then fill it up again with the files in the selected order.
  • Sort by name: very good for fast program starting. The files used by a particular program will be very close together on disk.
  • Sort by size: placing all the small files together at the beginning of the disk will dramatically reduce the average file seek time.
  • Sort by last access: files that have not been accessed in a while are probably unimportant and are best sorted to the back.
  • Sort by last change: placing files together that change a lot (for example databases and log files) will speed up regular operation of the system.
  • Sort by creation time: The oldest files on the disk are likely to be important system files, for example used when Windows is booting.
Note: If you want to sort by last access time then first make sure your virus scanner (and other programs that scan all files on disk) do not change that time.
Force together
Intended for partition resizing. All movable files are moved to the beginning of the disk, even if it means fragmenting them to fill gaps that cannot be filled otherwise.
Move to end of disk
Move all the files to the end of the disk, making more room at the beginning of the disk. Intended for big and rarely used files such as log files, backup archives, installation files, and such.

Frequently asked questions

I have set up a forum for JkDefrag, a place where you can ask questions, give feedback about features you would like, share your experiences, share code that uses the defragger library, and other things about JkDefrag.

 *  Jump to JkDefrag forum
What is "disk fragmentation"?
Imagine a book split into several parts, some pages are over here, other pages in another room on another floor altogether. You will have to walk a lot when you need to read the book. It may sound silly, but this is exactly what happens to files on your harddisk. Defragmentation will put all the parts (fragments) back together, making your computer a lot faster.

What is "disk optimization"?
Imagine a big library with lot's of books, spread out all over the building and not sorted whatsoever. There is an index telling you exactly where every book is, but you will have to walk a lot when you need several books. This is exactly what happens on your harddisk, the files that belong to an application can be all over the place, anywhere on the harddisk. Optimization will bring all the files together in one place, leaving the rest of the harddisk empty, and will sort the files, for example alphabetically.

How safe is it?
JkDefrag is based on the standard defragmentation API by Microsoft, a system library that is included in Windows 2000, 2003, XP, and Vista. Most defragmenters are based on this API, including commercial defragmenters. Basically all JkDefrag does is send "move this file to that location" commands to the API. It does not touch the disk by itself, and is therefore extremely solid. If your disks use NTFS then you're even safe when the computer crashes in the middle of defragmenting. Nevertheless, it's still a good idea to backup before defragmenting, just like with other defragmenters, because the heavy use of the harddisk may trigger a hardware fault (disk crash), and/or overheating (disk, power supply, controller chipset, etc.).

How do I specify an option, or select a single disk (or folder or file)?
Take a look at the GUI wrappers, see the "Contributed by other people" chapter. Personally I find the commandline the easiest way to specify options. Another way is to create a shortcut to "JkDefrag.exe", open the properties of the shortcut, and add the desired commandline options (for example "-a 7") or the name(s) of the disk/folder/file (for example "C:") to the end of the "target" line. For example:
"C:\JkDefrag\JkDefrag.exe" -a 7
"C:\JkDefrag\JkDefrag.exe" D:
Tip: In the same properties window you can select "minimized".
Tip: See the JkDefrag "-q" option to exit automatically when finished.

Where is the Stop button?
All versions of JkDefrag can be stopped safely at any time, there is no risk of losing data or corrupting your disk. You can use all the usual ways to stop a Windows program, such as pressing ALT-F4, clicking the 'x' in the top-right corner, via the pull-down menu in the taskbar, or by killing the program via the task manager or another utility. The commandline program can be stopped the same way, plus by pressing CTRL-C, or BREAK. It may take a bit of time for the program to actually stop, JkDefrag will finish the current file in the background.

Does JkDefrag support RAID Disks, USB disks, floppies, memory sticks?
Yes, no problem whatsoever. JkDefrag does not know anything about the underlying hardware, it leaves that up to Windows. It can therefore defragment and optimize anything and everything that behaves like a disk.
Note: Removable media (for example floppies) are not processed by default, but only when you specify the disk on the commandline (for example "jkdefrag G:").

What is the best defragmentation/optimization strategy for me?
My advise for all computers is to run JkDefrag once with the "-a 7" optimization (sort by name), and from then on automatically every day with the default "-a 3" fast-optimize option.
Note: The "-a 9" optimization (sort by last access time) only works as expected if you do not use programs that scan all files on disk (such as virus scanners and backup programs), causing Windows to update all the last access times.

How can I run JkDefrag automatically every day?
It's a great idea to run JkDefrag automatically every day by adding it to the Windows scheduler, like this:
  • Start -> Control Panel -> Scheduled Tasks -> Add Scheduled Task
  • The wizard starts, click 'Next'.
  • Use the 'browse' button to select the 'JkDefragCmd.exe' program.
  • Select 'daily', next, select a time, next.
  • Enter a userid/password with administrator privileges, click 'Finish'.
Note: The commandline version of JkDefrag ("jkdefragcmd.exe") will exit automatically when finished. See the "-q" option to do the same for the Windows version.
Tip: See the "Settings" of the scheduled task to run only when the computer is idle.
Tip: To start the task minimized, in the settings of the task change the commandline into "start /min JkDefragCmd.exe".
Tip: Use the windows version of JkDefrag ("jkdefrag.exe") to prevent Windows from switching to power-saving while JkDefrag is running.

How do I use the screensaver?
See the instructions in the "Install" chapter.

How to run JkDefrag at boot-time?
It's very easy to run JkDefrag automatically in the background when the computer starts via the Windows Task Scheduler:
  • Start -> Control Panel -> Scheduled Tasks -> Add Scheduled Task
  • The wizard starts, click 'Next'.
  • Use the 'browse' button to select the 'JkDefragCmd.exe' program.
  • Select 'When my computer starts', click next.
  • Enter a userid/password with administrator privileges, click 'Finish'.
Note: This will not defragment system files such as the page file. To do that see the "see also" chapter for a link to Pagedefrag, a free utility by Microsoft Technet (formerly SysInternals).

How to start minimized, or maximized?
Make a shortcut to the "JkDefrag.exe" program, open the properties of the shortcut, find the "run" setting, and select "minimized" or "maximized". To run the commandline-version in a minimized window use "start /min jkdefragcmd.exe".

How to run with a lower priority?
My advise is to use the JkDefrag"-s" commandline option to slow down the program, but you can change the process priority like this:
cmd.exe /c start "JkDefrag" /BelowNormal "jkdefragCmd.exe"

How much minimum free disk space does JkDefrag require?
JkDefrag does not require a minimum free disk space, unlike many other defragmenters. But:
  • Windows reserves some space for expansion of the MFT, default is 12.5% of the volume size. This space is counted by Windows as free space because it can/will be used for regular files when the rest of the volume is full. But JkDefrag cannot use this free space.
  • A file can only be defragmented if there is a gap on disk big enough to hold the entire file. There may be plenty of free space, but what is needed is a single big gap. In these cases JkDefrag will try to reduce the number of fragments in the file by using the biggest gaps available.

Why is my disk not perfectly optimized?
  • There are many files that cannot be moved while Windows is running, because they are in use by an application, or by a service, or by Windows itself. See the "-d" commandline options and the logfile for more information. They can be anywhere on disk and are usually fragmented into microscopically small segments. In other words, the harddisk is not a big block of space where files can be moved at will, but thousands of little blocks bounded by unmovable data.
    A typical harddisk can easily contain tens of thousands of files, all with different sizes. What is the optimum way to organize the files into the blocks? The number of permutations is astronomical, it boggles the mind. JkDefrag doesn't even try to calculate them all. It concerns itself with only one block at a time, trying to fit only files from above the block, and limits itself to 0.5 seconds of calculating time.
    So it's very unlikely, if not impossible, for JkDefrag to perfectly optimize your disk, more's the pity.
  • Gaps are only filled with files from above the gap (fast optimization). If there are no files that fit the gap (all files are bigger) then the gap cannot be filled.
  • Files can only be fully defragmented if there is a gap large enough to hold the entire file. If no such gap is available then JkDefrag will try to reduce the number of fragments by moving the file to the largest gaps available.
  • JkDefrag maintains a "free space" area between the directories and the regular files, and between the regular files and the SpaceHogs. This is by design. See the "-f" commandline option to control the size of these free spaces.

Why do the sorting optimizations create fragments?
The sorting optimizations will move all the data to the beginning of the harddisk. But there may be some unmovable files in the way. Instead of leaving gaps (if a file doesn't fit between the last file and the unmovable file), the program will "wrap around" the unmovable files by splitting regular files into fragments. This may seem strange for a defragmenter, but the fragments are aligned and therefore have a very small impact on performance. Gaps however would make all the files above the gaps slower, because they would then be placed at a slightly slower part of the harddisk than they need to be. The fragments look terrible on the screen and in the statistics, but are there to make your harddisk faster!

What speed can I expect?
It is impossible to predict how long a defragment/optimize will take. It depends on things such as the optimization you have selected, the speed of your harddisk, how big the files are, how much data is on the disk, and more. Assuming a harddisk speed of 40 megabyte per second, then reading 100 gigabyte of data will take 100000 / 40 = 2500 seconds (42 minutes). But JkDefrag has to do a lot more than just read the data, it also has to write the data, and update the MFT/FAT. And it may have to move data out of the way before it can place an item were it want's it to be. JkDefrag will do things as efficiently as possible, with as little data movement as possible, but it will take a long time nonetheless. If you are concerned about speed then use the default "-a 3" (fast optimize) setting. It will produce very good results in a minimum amount of time, especially if you use it every day.

What are SpaceHogs?
SpaceHogs are less important files that take up a lot of space. JkDefrag moves them behind the directories and the regular files, to make those faster. The internal list of SpaceHogs is (you can add more with the "-u" commandline option):
  • Files bigger than 50 megabytes
  • Files not accessed in the last month
  • ?:\$RECYCLE.BIN\*
  • ?:\RECYCLED\*
  • ?:\RECYCLER\*
  • ?:\WINDOWS\$*
  • ?:\WINDOWS\Downloaded Installations\*
  • ?:\WINDOWS\Ehome\*
  • ?:\WINDOWS\Fonts\*
  • ?:\WINDOWS\Help\*
  • ?:\WINDOWS\I386\*
  • ?:\WINDOWS\IME\*
  • ?:\WINDOWS\Installer\*
  • ?:\WINDOWS\ServicePackFiles\*
  • ?:\WINDOWS\SoftwareDistribution\*
  • ?:\WINDOWS\Speech\*
  • ?:\WINDOWS\Symbols\*
  • ?:\WINDOWS\ie7updates\*
  • ?:\WINDOWS\system32\dllcache\*
  • ?:\WINNT\$*
  • ?:\WINNT\Downloaded Installations\*
  • ?:\WINNT\I386\*
  • ?:\WINNT\Installer\*
  • ?:\WINNT\ServicePackFiles\*
  • ?:\WINNT\SoftwareDistribution\*
  • ?:\WINNT\ie7updates\*
  • ?:\*\Installshield Installation Information\*
  • ?:\I386\*
  • ?:\System Volume Information\*
  • ?:\windows.old\*
  • *.7z
  • *.arj
  • *.avi
  • *.bak
  • *.bup
  • *.bz2
  • *.cab
  • *.chm
  • *.dvr-ms
  • *.gz
  • *.ifo
  • *.log
  • *.lzh
  • *.mp3
  • *.msi
  • *.old
  • *.pdf
  • *.rar
  • *.rpm
  • *.tar
  • *.vob
  • *.wmv
  • *.z
  • *.zip
Note: Some virus scanners and other programs that scan all files on disk, will change the last access time of all items on every run, effectively disabling that particular SpaceHogs criterion. The other criteria still apply, though.

Can I run JkDefrag outside Windows?
JkDefrag is based on the Windows defragmentation library, so Windows must be started. JkDefrag can be run from a bootable Windows CD-rom (such as  *  Bart's Preinstalled Environment (BartPE) or  *  Ultimate Boot CD for Windows ), but cannot be run from a DOS bootable floppy or from Linux.
Tip: Boot into Windows safe mode by pressing F8 when booting, and then run JkDefrag. It will be slower (the Windows cache is off in safe mode), but you can defragment more files.
Warning: Do not hybernate your computer, boot with something else (such as BartPE), and then change the hybernated disk in any way. This will corrupt the disk, a known hybernation problem. JkDefrag refuses to process hybernated disks.

Can JkDefrag do continuous background defragmenting?
In my opinion continuous background defragmenting and optimization is marketing hype and a bad idea. There is considerable overhead (CPU, memory, disk) that may actually make your computer slower instead of faster, and it will wear out and shorten the life span of your harddisk. I advise defragmenting once a day (via the Windows Task Scheduler) at the most.

What is the "Average end-begin distance"?
When Windows has finished reading a file then the harddisk heads will have to move to the beginning of whatever file is needed next. JkDefrag calculates the average distance from the end of every file to the beginning of every other file, and shows this number in the report (see the logfile). A lower number means that the files are better packed together and can be accessed more quickly.
Note: The lowest possible average distance can be achieved by sorting by filesize.

Can I "hide" the program from users?
See the "How to start minimized, or maximized?" question. Running completely invisible is a bit more difficult. Create a special userid (for example "jkdefrag") with administrator permissions, then add a schedule to the Windows Task Scheduler (see the "How can I run JkDefrag automatically every day?" question) and specify that userid when asked for. The task will then run on that userid and not show anything on the user's screen. But I advise against it, I think it will needlessly worry the user when he sees a lot of mysterious disk activity.

Why is JkDefrag so slow in Windows "safe" mode?
The Windows disk cache is off in "safe" mode.

How do I disable the Windows built-in defragger?
Windows 2000 & 2003:
The built-in defragger is not started automatically.
Windows XP:
  1. Download the free  *  Tweak UI utility from Micorosft.
  2. Click on 'General' and untick the 'Optimise hard disk when idle' box.
Windows Vista:
  1. Start -> All Programs -> Accessories -> System Tools -> Disk Defragmenter
  2. Untick the "Run on a schedule (recommended)" box.

How do I defragment "c:\pagefile.sys"?
One way is to download and install the free  *  Pagedefrag utility by Microsoft TechNet (formerly Sysinternals), it will automatically defragment the pagefile and some other system files when the system is booting. But even better is to set the pagefile to a fixed size, so it will never get fragmented again. It's very easy to do:
  1. Windows Vista: Open the "Control Panel", classic view. Double click "system". Select "Advanced system settings". Click the Performance "Settings" button. Select the "Advanced" tab. Click the Virtual Memory "Change" button.
    Windows 2000: Open the "Control Panel". Double click "system". Select the "advanced" tab. Click the "Performance Settings" button. Click the Virtual Memory "Change" button.
  2. Write down the "Currently Allocated" number.
  3. Windows Vista: Select "no paging file" for all disks.
    Windows 2000: Set the Initial Size and the Maximum Size numbers for all disks to zero.
  4. Reboot.
  5. Run JkDefrag.
  6. Go back to the same panel and setup a pagefile with a "custom size" where both the Initial Size and the Maximum Size are the number you wrote down.
  7. Reboot again. The pagefile should now be a single big unfragmented file that will never get fragmented again.

How do I defragment "C:\hiberfil.sys"?
This huge file is used by the hibernation facility and cannot be defragmented on a running system. You can only delete the file, like this:
Windows Vista:
  1. Click Start -> All Programs -> Accessories, right click on "Command Prompt", and then click "Run as Administrator". If User Account Control (UAC) asks you for permission, permit the Command Prompt to run.
  2. Enter "powercfg -h off" (without the quotes).
  3. Reboot. The "hiberfil.sys" file will be automatically deleted.
  4. Repeat point 1
  5. Enter "powercfg -h on" (without the quotes).
  6. Reboot.
Windows XP:
  1. Open the Control Panel
  2. Double-click Power Options
  3. Click the Hibernate tab, de-select the 'Enable hibernate support' check box, and then click Apply.
  4. Reboot. The "hiberfil.sys" file will be automatically deleted.
  5. Go to the Windows Help & Support Center and search for 'enable hibernation'. It should be the first result. The instructions detail some other steps you may need to follow to reactivate the hibernation.

Why does JkDefrag delete my restore points?
It's not JkDefrag that is deleting your restore points. Restore points use the Shadow Copy service to make snapshots of the disk. JkDefrag does not change files (it only defragments or moves them), but it does change the disk (moving a file is a change to the disk). The Shadow Copy service remembers all these changes in big files in the "C:\System Volume Information\...." folder. When the total amount of diskspace used by shadow copies exeeds a threshold then the oldest snapshot (restore point) is automatically deleted. The threshold can be changed with the "vssadmin" command, see the  *  vssadmin manpage.

How do I defragment "C:\System Volume Information\...."?
These huge files are used by the Shadow Copy service, which in turn is used by the System Restore facility and by Windows backup. The files can be defragmented on XP by stopping the Shadow Copy service ("srservice"). They cannot be defragmented on Vista. You can cleanup old shadow copies with "Start -> Programs -> Accessories -> System Tools -> Disk Cleanup", the "More Options" tab. Or you can turn off System Restore altogether like this:
Windows Vista:
  1. In Control Panel, click "System".
  2. Select "System Protection".
  3. If a disk has a checkmark then remove the checkmark.
Windows XP:
  1. Open the properties of "My Computer".
  2. Select the "System Restore" tab. If you do not see the System Restore tab then you are not logged on to Windows as an Administrator.
  3. Check "Turn off System Restore" or "Turn off System Restore on all drives".

How do I defragment "C:\$Extend\$UsnJrnl:$J:$DATA"?
This huge file is used by Windows to track changes in other files and cannot be defragmented. You can delete it by entering the following on the Run commandline (Windows 2003/XP/Vista, not Windows 2000), it can take several minutes to finish:
fsutil usn deletejournal /n c:
Note: See  *  fsutil manpage

Why use this defragger instead of the standard Windows defragger?
  • Much faster.
  • Totally automatic, extremely easy to use.
  • Optimized for daily use.
  • Data optimization, several strategies.
  • Directories are moved to the beginning of the disk.
  • Reclaims MFT reserved space after disk-full.
  • Maintains free spaces for temporary files.
  • Can defragment very full harddisks.
  • Can defragment very large files.
  • Can defragment individual directories and files.
  • Can be run automatically with the Windows Scheduler.
  • Can be used from the commandline.
  • Can be used as a screen saver.
  • Can be run from cdrom or memory stick.
  • Sources available, can be customized.

Why use this defragger instead of a commercial or shareware defragger?
  • It's free.
  • Totally automatic, extremely easy to use.
  • Optimized for daily use.
  • Several optimization strategies.
  • Directories are moved to the beginning of the disk.
  • Reclaims MFT reserved space after disk-full.
  • Maintains free spaces for temporary files.
  • Can defragment individual directories and files.
  • Can be used from the commandline.
  • Can be used as a screen saver.
  • Can be run from cdrom or memory stick.
  • Sources available, guaranteed to be free of spyware, malware, nagware, and such.

Tip: See the  *  JkDefrag forum!!!

Known problems

  • Some data on an NTFS partition may become corrupted after you restart a Windows XP-based computer that uses a SATA hard disk drive. This is not a JkDefrag bug but a Microsoft defragmentation API bug. Microsoft have released a bugfix, see:  *  Bugfix 941715
  • Some kinds of external disks cannot be defragmented and optimized, especially network disks that use their own internal operating system and special dedicated filesystem. The drivers of these disks simply do not support it. This is not a JkDefrag bug.
  • The "Prefetch\Layout.ini" file is not yet supported. This means that JkDefrag will undo the boot optimization of the built-in XP and Vista defragger.
  • Files that are encrypted by Windows can be defragmented and optimized, but their $EFS:$LOGGED_UTILITY_STREAM counterpart cannot. The Windows CreateFile() system call refuses to open these files and I have not yet found a workaround.
  • The Microsoft defragmentation API on Vista can defragment and move the MFT, but JkDefrag cannot use this capability yet.
  • The Windows defragmentation API refuses to move directories on FAT32 filesystems. This is a known FAT32 limitation and not a bug in JkDefrag.
  • The Windows defragmentation API on Windows 2000 does not work on disks that were formatted with a clustersize greater than 4KB. This is a known API limitation and not a bug in JkDefrag. There is no risk of losing data, the API simply refuses to move files.
  • A user has reported that his computer freezes when Avira Antivir Professional starts while the JkDefrag screensaver is active.
  • A user has sent me a message that HP advises against defragmentation of the special "recovery" partition on their computers. My defragger uses the standard Microsoft defragmentation API, so I think it is safe to use, but I don't know for sure. I have not found any additional information about this issue anywhere on the internet.
  • JkDefrag makes a special exception for files used by SafeBoot, Acronis OS Selector, SecurStar DriveCrypt, and Symantec GoBack. The files will never be moved. If you know of any other software that needs a special exception then please let me know.

Contributed by other people

JkDefrag was designed to be fully automatic and is extremely easy to use. Most users can use the program as-is. The GUI wrappers described below can be useful if you have special requirements and are easier to use than the commandline options.

 *  French version
JkDefrag and all the docs translated into French by Sparad0x. Included are a Setup program and the sources, and a special version for U3 flash drives.
 *  German version
JkDefrag and all the docs translated into German by Markus H÷rl. Also available is a Setup program and a GUI wrapper.
 *  Spanish version
JkDefrag and all the docs translated into Spanish by Manuel Montero. Also available is a translated version of Emiel Wieldraaijer's GUI.
 *  Italian version
All the docs (not the program itself) translated into Italian by Danilo Angaroni.
 *  Traditional Chinese version
JkDefrag (the program, not the docs) translated into Traditional Chinese by Eddy Guo. Also available is a GUI. Sources included.
 *  JkDefragGui
GUI program by Emiel Wieldraaijer. JkDefragGUI is available in the following languages: Brazilian Portuguese, Bulgarian, Catalan, Czech, Dutch, Chinese (Traditional and Simplified), English, French, German, Greek/Hellenic, Hebrew, Hungarian, Italian, Japanese, Swedish, Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovenian, Spanish and Valencian. Also availiable an U3 Version and BartPe Plugin.
 *  JkDefragGui
GUI program by Dirk Paehl. In English. Sources are included.
 *  JkDefragTWGUI
GUI program by Thorsten Willert. Can handle multiple "jobs". In English, although the homepage is in German.
 *  JkDefragStarter
GUI program in German by Thomas Kolb. C++ sources are included.
 *  Donn's JkDefrag Installer
Installer (setup) program for JkDefrag by Donn Edwards (see the chapter about JkDefrag). Includes several other utilities: NtRegOpt, PageDefrag, JkDefrag GUI, and Contig.
 *  Myriades JkDefrag Installer
Installer (setup) program for JkDefrag by Myriades. Includes the 32 and 64 bits versions, sources, licence. It creates a start menu shortcut for the program, project, logfile, and uninstall.

See also

 *  JkDefrag forum
I have set up a forum for JkDefrag, a place where you can ask questions, give feedback about features you would like, share your experiences, share code that uses the defragger library, and other things about JkDefrag.

 *  HD Tune
Measure your harddisk and discover how much faster it is at the beginning than at the end. Can also monitor the temperature of your harddisk and scan for surface errors.

 *  Defragmentation
Wikipedia page about defragmentation.

 *  Pagedefrag by Microsoft TechNet (formerly Sysinternals)
Paging files and registry hives cannot be defragmented on a running system. This sweet little utility will automatically defragment those files when the system is booting. The counterpart of this utility is "Contig", a small defragger for use on a running system, but my defragger is far superior.

 *  DiskView by Microsoft TechNet (formerly Sysinternals)
Small utility that shows which file is using a particular location on the harddisk. Use this if you are wondering which file JkDefrag could not move. The utility takes a while to start up, because it has to analyze all files one by one, but it's a very nice little utility nevertheless.
 *  HDview
Similar utility as DiskView, by Alexander Freudenberg. Much faster and for NTFS only.

 *  Windows Server 2003 Resource Kit Tools
A free collection of tools from Microsoft. Amongst other things it contains a "sleep.exe" utility that could be used to make a little .bat file to delay-start JkDefrag when booting the computer.

 *  ScanDefrag
A very nice utility that will run maintenance programs as early as possible in the Windows startup. My defragger is one of the supported programs, others are for example Microsoft's Disk Cleanup, ScanDisk/Chkdsk, Norton's Disk Doctor, and others.

 *  AutoRuns by Microsoft TechNet (formerly Sysinternals)
Handy utility to discover all the things that are started when windows is booting.